package com.wd.live.module_my.view.activity

import android.graphics.Typeface
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.TypedValue
import android.view.Gravity
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.google.android.material.tabs.TabLayout
import com.wd.live.module_base.net.bean.wide.FindGiftRecordByUidBean
import com.wd.live.module_base.ui.base.BaseActivity
import com.wd.live.module_my.R
import com.wd.live.module_my.databinding.ActivityGiftRecordByUidBinding
import com.wd.live.module_my.view.adapter.GiftRecordByUidAdapter
import com.wd.live.module_my.viewmodel.MyViewModel
import java.text.SimpleDateFormat
import java.util.Date
@Route(path = "/my/giftrecordbyuid_activity")
class GiftRecordByUidActivity : BaseActivity<MyViewModel,ActivityGiftRecordByUidBinding>() {
    val titleArr= mutableListOf<String>("我收到的","我送出的")
    override fun getLayout(): Int {
        return R.layout.activity_gift_record_by_uid
    }
    var type:Int=1
    var labsGiftArr= mutableListOf<FindGiftRecordByUidBean>()

    override fun initData() {
        titleArr.forEach{title->
            binding.tbGift.addTab(binding.tbGift.newTab().setText(title))
        }
        viewModel.getFindGiftRecordByUid(type,1,10)
        viewModel.dataFindGiftRecordByUid.observe(this){
            it.result.let {
                it1->
                if (it1 != null) {
                    labsGiftArr.clear()
                    labsGiftArr.addAll(it1)
                }
                binding.giftRv.adapter?.notifyDataSetChanged()
                  }
            binding.giftRv.adapter=GiftRecordByUidAdapter(this,R.layout.gift_item,labsGiftArr)
            val linearLayoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
            binding.giftRv.layoutManager=linearLayoutManager
            binding.tbGift.addOnTabSelectedListener(object :TabLayout.OnTabSelectedListener{
                override fun onTabSelected(tab: TabLayout.Tab?) {
                    if (tab != null) {
                        type=tab.position+1
                        viewModel.getFindGiftRecordByUid(type,1,10)
                    }
//                    setTab(tab)
                }

                override fun onTabUnselected(tab: TabLayout.Tab?) {

                }
                override fun onTabReselected(tab: TabLayout.Tab?) {

                }

            })
        }


    }





    //选中切换大小
//    fun setTab(tab: TabLayout.Tab?){
//        val textView= TextView(this)
//        //字体样式
//        val selectedSize =
//            TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, 20f, resources.displayMetrics)
//        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, selectedSize)
//        textView.typeface = Typeface.defaultFromStyle(Typeface.BOLD) //加粗
//        textView.gravity = Gravity.CENTER
//        //选中的字体颜色
//        //textView.setTextColor(ContextCompat.getColor(context, Color.BLACK))
//        textView.text = tab!!.text
//        tab.customView = textView
//
//    }
    override fun getViewModelClass(): Class<MyViewModel> {
        return MyViewModel::class.java
    }

}